package com.doubleview.commons;

import cn.hutool.core.comparator.VersionComparator;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ReUtil;
import org.junit.Test;

import java.io.File;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

public class FileUtilsTest {

    public static void main(String[] args) throws Exception {
        Date expireEndTime = DateUtil.beginOfDay(new Date());
        System.out.println(expireEndTime.getTime());
    }


    @Test
    public void testDelete() {
        for (File file : FileUtil.newFile("/Users/huchengchao/.m2/repository/kuaishou").listFiles(File::isDirectory)) {
            File[] subFiles = file.listFiles(File::isDirectory);
            String maxVersion = Arrays.asList(subFiles).stream().map(File::toString).max(new VersionComparator()).orElse(null);
            for (File toDelete : file.listFiles(File::isDirectory)) {
                if (!toDelete.getPath().equals(maxVersion)) {
                    System.out.println(file.getName() + ",   toDelete: " + toDelete);
                    FileUtil.del(toDelete);
                }
            }
        }
    }
}